﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ShareMarking.Interface;
using MySoft.Data;
using ShareMarking.Entity;
using ShareMarking.Service;

namespace ShareMarking.Web.Test
{
    public partial class check : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DbSession.Default.FromSql("DELETE qr_check").Execute();

            DataTable table = new DataTable();
            string sql = @"SELECT nc.nc_code,qr.scene_id,qr.qrcode_url,qr.code_url,qr.wx_title,qr.wx_content,qr.wx_imgurl,qr.wx_url
from nc_ncuser nc left join qr_QrCodeRelate rel on nc.nc_code=rel.rel_Code 
left join qr_QrCode qr on rel.qr_Scene_ID=qr.scene_id where rel.IsDelete=0";

            table = DbSession.Default.FromSql(sql).ToTable();
            table.TableName = "checktb";

            CheckQrcode check = new CheckQrcode();
            Qrcode_vigo vigo = new Qrcode_vigo("http://my.erpcoo.com/index.php/Api/Qrcode/index", "sdf5sf5et5e42t5");

            for (int i = 0; i < table.Rows.Count; i++)
            {
                var imgurl = table.Rows[i]["qrcode_url"].ToString();
                var qrcodecontent = check.getqrcontent(imgurl);
                var resultwx = vigo.GetWXContent("", table.Rows[i]["scene_id"].ToString());
                var retitle = resultwx.message[0].title;
                var redesc = resultwx.message[0].shortdesc;
                var repicurl = resultwx.message[0].picurl;
                var relinkurl = resultwx.message[0].linkurl;

                qr_Check qrc = new qr_Check()
                {
                    qrtype = "1",
                    rel_code = table.Rows[i]["nc_code"].ToString(),
                    scene_id = table.Rows[i]["scene_id"].ToString(),

                    code_url = table.Rows[i]["code_url"].ToString(),
                    httpcode_url = qrcodecontent,
                    iseqccode_url = (table.Rows[i]["code_url"].ToString() == qrcodecontent),

                    //wxtitle = "【美赞臣】微信注册", //table.Rows[i]["wx_title"].ToString(),
                    //httpwxtitle = retitle,
                    //iseqwxtitle = ("【美赞臣】微信注册" == retitle),

                    //shortdesc ="注册成为会员，享受更多优惠折扣！", //table.Rows[i]["wx_content"].ToString(),
                    //httpshortdesc = redesc,
                    //iseqshortdesc=("注册成为会员，享受更多优惠折扣！"==redesc),

                    //picurl ="http://svr.meadjohnson.com.cn/mjnwx/css/images/logo_b.png" ,//table.Rows[i]["wx_imgurl"].ToString(),
                    //httppicurl = repicurl,
                    //iseqpicurl = ("http://svr.meadjohnson.com.cn/mjnwx/css/images/logo_b.png"==repicurl),

                    //linkurl = "http://svr.meadjohnson.com.cn/mjnwx/client_phone.action?NCCode=" + table.Rows[i]["nc_code"].ToString() + "$openId=####",//table.Rows[i]["wx_url"].ToString(),
                    //httplinkurl = relinkurl,
                    //iseqlinkurl = (("http://svr.meadjohnson.com.cn/mjnwx/client_phone.action?NCCode=" + table.Rows[i]["nc_code"].ToString() + "$openId=####") == relinkurl)
                };
                qr_CheckService.Instance.Add_Entity(qrc);
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            var ss = "http://my.erpcoo.com/Uploads/ercode/20160219/145584573645958.png";

            CheckQrcode check = new CheckQrcode();
            
            var sss = check.getqrcontent(ss);

            Response.Write(sss);
        }
    }
}